const hash = require('../secret/index.js');

var redis =require('redis');
const client = redis.createClient('6379','127.0.0.1');
var ready	=client.connect()
			client.on('error', err=>{ throw '请检查redis报错'});
				
//时间戳
function randomStr(){
	var date=new Date()
	return date.getTime();
}
class success {
	constructor(arg) {
	    
	};
	set(key,value){
			return new Promise(async (resolve,reject)=>{
				await ready;
				key=hash.Encrypte(key)
				client.set(key,value).then(
					success=>{
						client.expire(key,60*10);
						resolve(key)
					},
					fail=>{
						reject(fail)
					}
				)
			})
	};
	get(key){
		return new Promise(async (resolve,reject)=>{
			await ready;
			client.get(key).then(
				result => resolve(result),
				err => reject(null)
			)
		})
	}
}

 
module.exports= new success()

